//
//  str.hpp
//  Cpp_Demo
//
//  Created by Robin Guo on 2017/9/24.
//  Copyright © 2017年 Robin Guo. All rights reserved.
//

#ifndef str_hpp
#define str_hpp

#include <stdio.h>
#include <iostream>
using namespace std;

class str {
    char *st;
    
public:
    str(char *s);
    str(str &);
    str& operator=(char *);
    str& operator=(str &);
    void print() { cout << st << endl; }
    ~str();
};

str::str(char *s) {
    st = new char[strlen(s)+1];
    strcpy(st, s);
}

str::str(str &s){
    st = new char[strlen(s.st)+1];
    strcpy(st, s.st);
}

str& str::operator=(char *s) {
    delete st;
    st = new char[strlen(s)+1];
    strcpy(st, s);
    return *this;
}

str& str::operator=(str& s) {
    if (this == &s) {
        return *this;
    }
    
    delete st;
    st = new char[strlen(s.st) + 1];
    this->st = strcpy(st, s.st);
    return *this;
}

str::~str() {
    delete st;
}


#endif /* str_hpp */
